package com.fenmirs.bookmarks.mvc;

import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @author fenmirs
 * @create 2019-05-22 10:45
 * simple description of this file
 */
@Mapper
public interface BookmarksMapper{
    @Select("select * from bookmarks where user_id = #{userId} order by bookmark_index asc")
    List<BookmarksVo> findAllOfUser(@Param("userId") String userId);

    @Delete("delete from bookmarks where user_id = #{userId}")
    int deleteOfUser(@Param("userId") String userId);


    @Insert(   "<script>"
            + "INSERT INTO bookmarks(id,bookmarks_id,bookmark_name,bookmark_url,parent_dir_id,bookmark_index,user_id,createTime)"
            + " VALUES "
            + "<foreach separator= ',' index= 'index' item= 'item' collection= 'insertList'  close= ''  open= '' >"
            + "(#{item.id},#{item.bookmarksId},#{item.bookmarkName},#{item.bookmarkUrl},"
            + "#{item.parentDirId},#{item.bookmarkIndex},#{item.userId},#{item.createTime})"
            + "</foreach>"
            +"</script>")
    int addAll(@Param("insertList") List<BookmarksVo> insertList);
}
